
/* Copyright ©, 2022, ECARX (Hubei) Technology Co., Ltd. All rights reserved.
 *
 * NOTICE: This file contains information which is confidential and proprietary to ECARX
 * (Hubei) Technology Co., Ltd. and/or other developers. No license to any intellectual
 * property rights contained within this file is either granted or implied except as may be
 * provided in an agreement with ECARX (Hubei) Technology Co., Ltd.
 *
 * Any unauthorized copying or distribution of content from this file in whole or in part
 * is prohibited.
 */
#include <vhal_v2_0/VehicleHalManager.h>

#include "EmulatedVehicleConnector.h"
#include "EmulatedVehicleHal.h"
#include "VendorVehicleHal.h"

namespace ecarx::vhal::impl {

using namespace android::hardware::automotive::vehicle::V2_0;
using namespace android::hardware::automotive::vehicle::V2_0::impl;
class VehicleHal::VehicleHalImpl {
    std::unique_ptr<VehiclePropertyStore> store;
    PassthroughConnectorPtr connector;
    std::unique_ptr<EmulatedVehicleHal> hal;
    std::unique_ptr<VehicleEmulator> emulator;
    core::interface::IVendorVehicleServer* mserver;

  public:
    VehicleHalImpl(core::interface::IVendorVehicleServer* server)
        : store(std::make_unique<VehiclePropertyStore>()),
          connector(makeEmulatedPassthroughConnector()),
          hal(std::make_unique<EmulatedVehicleHal>(store.get(), connector.get(),connector.get(), server)),
          emulator(std::make_unique<VehicleEmulator>(hal.get())),
          mserver(server) {}
    std::unique_ptr<VehicleHalManager> createVhalManager() {
        auto service = std::make_unique<VehicleHalManager>(hal.get());
        connector->setValuePool(hal->getValuePool());
        connector->setVendorImpl(mserver);
        return service;
    }
};

VehicleHal::VehicleHal(core::interface::IVendorVehicleServer* server)
    : mImpl(new VehicleHalImpl(server)) {}

VehicleHal::~VehicleHal() {
    delete mImpl;
}

std::unique_ptr<VehicleHalManager> VehicleHal::createVhalManager() {
    return mImpl->createVhalManager();
}
}  // namespace ecarx::vhal::impl
